package com.xiaoze.question.controller;

import java.util.List;

import com.xiaoze.question.dto.QuestionItemsOutput;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xiaoze.common.annotation.Log;
import com.xiaoze.common.core.controller.BaseController;
import com.xiaoze.common.core.domain.AjaxResult;
import com.xiaoze.common.enums.BusinessType;
import com.xiaoze.question.domain.QuestionItems;
import com.xiaoze.question.service.IQuestionItemsService;
import com.xiaoze.common.utils.poi.ExcelUtil;
import com.xiaoze.common.core.page.TableDataInfo;

/**
 * 试题题目管理Controller
 *
 * @author 胡昊泽
 * @date 2024-08-02
 */
@RestController
@RequestMapping("/question/items" )
public class QuestionItemsController extends BaseController {
    @Autowired
    private IQuestionItemsService questionItemsService;

    /**
     * 查询试题题目管理列表
     */
    @PreAuthorize("@ss.hasPermi('question:items:list')" )
    @GetMapping("/list" )
    public TableDataInfo list(QuestionItems questionItems) {
        startPage();
        List<QuestionItemsOutput> list = questionItemsService.selectQuestionItemsList(questionItems);
        return getDataTable(list);
    }

    /**
     * 导出试题题目管理列表
     */
    @PreAuthorize("@ss.hasPermi('question:items:export')" )
    @Log(title = "试题题目管理" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(QuestionItems questionItems) {
        List<QuestionItemsOutput> list = questionItemsService.selectQuestionItemsList(questionItems);
        ExcelUtil<QuestionItemsOutput> util = new ExcelUtil<>(QuestionItemsOutput.class);
        return util.exportExcel(list, "items" );
    }

    /**
     * 获取试题题目管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('question:items:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(questionItemsService.selectQuestionItemsById(id));
    }

    /**
     * 新增试题题目管理
     */
    @PreAuthorize("@ss.hasPermi('question:items:add')" )
    @Log(title = "试题题目管理" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QuestionItems questionItems) {
        return toAjax(questionItemsService.insertQuestionItems(questionItems));
    }

    /**
     * 修改试题题目管理
     */
    @PreAuthorize("@ss.hasPermi('question:items:edit')" )
    @Log(title = "试题题目管理" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QuestionItems questionItems) {
        return toAjax(questionItemsService.updateQuestionItems(questionItems));
    }

    /**
     * 删除试题题目管理
     */
    @PreAuthorize("@ss.hasPermi('question:items:remove')" )
    @Log(title = "试题题目管理" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(questionItemsService.deleteQuestionItemsByIds(ids));
    }
}
